#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
商户主结算卡查询模型
"""

from typing import Dict, Any, Optional
from dataclasses import dataclass, asdict
from jlpay.model.base import OrgBaseReq, BaseResponse
from jlpay.utils.annotation_utils import Decrypt, SensitiveField


class MerchMasterSettCardQueryRequest(OrgBaseReq):
    """商户主结算卡查询请求参数"""
    
    API_URL = "/open/merch/access/merch-settle-info/query"
    
    def __init__(self):
        """初始化商户主结算卡查询请求"""
        super().__init__()
        self.merch_no = None
    
    def set_merch_no(self, merch_no: str):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            MerchMasterSettCardQueryRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def to_dict(self) -> Dict[str, Any]:
        """转换为字典格式"""
        return super().to_dict()


@Decrypt
class MerchMasterSettCardQueryResponse(BaseResponse):
    """商户主结算卡查询响应参数"""
    
    def __init__(self, response_dict=None):
        """
        初始化响应对象
        
        Args:
            response_dict: 响应字典
        """
        # 先调用父类初始化，处理ret_code, ret_msg等基础字段
        super().__init__(response_dict)
        
        # 定义需要解密的敏感字段路径（对应Java源码中的@Decrypt注解字段）
        self._sensitive_fields = [
            SensitiveField("account_name"),  # 户名
            SensitiveField("account_no"),    # 账号
        ]
        
        # 初始化特定字段
        self.merch_no = ""  # 商户号
        self.merch_name = ""  # 商户名称
        self.settle_type = ""  # 结算类型
        self.account_name = ""  # 户名 (需要解密)
        self.account_no = ""  # 账号 (需要解密)
        self.bank_code = ""  # 开户银行编码
        self.bank_branch_id = ""  # 开户支行编号
        self.bank_branch_name = ""  # 开户支行名称
        
        if response_dict:
            # 从response_dict中提取特定字段，避免与父类字段冲突
            self.merch_no = response_dict.get('merch_no', '')
            self.merch_name = response_dict.get('merch_name', '')
            self.settle_type = response_dict.get('settle_type', '')
            self.account_name = response_dict.get('account_name', '')
            self.account_no = response_dict.get('account_no', '')
            self.bank_code = response_dict.get('bank_code', '')
            self.bank_branch_id = response_dict.get('bank_branch_id', '')
            self.bank_branch_name = response_dict.get('bank_branch_name', '')

    def get_sensitive_fields(self):
        """
        返回需要解密的敏感字段路径列表
        
        Returns:
            包含敏感字段路径的列表
        """
        return self._sensitive_fields

    def to_dict(self) -> Dict[str, Any]:
        """转换为字典格式"""
        data = super().to_dict()
        data['merch_no'] = self.merch_no
        data['merch_name'] = self.merch_name
        data['settle_type'] = self.settle_type
        data['account_name'] = self.account_name
        data['account_no'] = self.account_no
        data['bank_code'] = self.bank_code
        data['bank_branch_id'] = self.bank_branch_id
        data['bank_branch_name'] = self.bank_branch_name
        return data 